var mouseX;
var mouseY;
var setTimeoutVal = 50;
$(function(){
	
	$(":password").attr("autocomplete","off");
	
	$(":text").blur(function(){
		this.value = doTrim(this.value);
	});
	
	//如果是Chrome
	if(window.navigator.userAgent.indexOf("Chrome") !== -1 ){
	    $(".thisCt").css("top","20px");
	}
	
	if($('body',parent.document).attr("id")=='main'){
		editParentHeight();
	}
	//当前内嵌页面高度被改变的时候，改变父页面iframe的高度
	$('body').contents().resize(function() {
		var bodyID = $('body').attr("id");
		if(bodyID=='main' || bodyID=="reqBody")return;
		editParentHeight();
	});
	
	//所有a标签鼠标移动上去变成红色
    var acolor;
	$("a").mouseover(function(){
		acolor = $(this).css("color");
		$(this).css("color","#e73737");
	});
	$("a").mouseout(function(){
		$(this).css("color",acolor);
	});
	//所有密码框被点击时全选
	$("input").click(function(){
		if($(this).attr("type")=="password"){
			$(this).select();
		}
    });
	//当前鼠标点击位置
	$(document).click(function (ev) { 
		var oEvent=ev||event;
		mouseX=oEvent.clientX;
		mouseY=oEvent.clientY;
	});
	
	//修改火狐中当前选中商户提示的位置
	if (navigator.userAgent.indexOf('Firefox') >= 0){$(".thisCt").css("top","22px");}
});
//将当前页面内容的高度值设置到父页面的iframe中
function editParentHeight(){
	var thisHeight = document.body.scrollHeight;
	var formList = $("form");
	if(formList!=undefined && formList.length==1){
		thisHeight = parseInt($($("form")[0]).css("height"));
	}
    parent.parent.editIfrHeight(thisHeight+100);
}

//页面跳转
function toUrl(url){
	location.href = url;
}

//跳转指定TARGE
function toTargeUrlt(url,targe)
{
	targe.location=url;
}

//父页面返回顶部
function parentToTop(){
	if($("body",parent.parent.parent.parent.document).attr("id")=="main"){
		parent.parent.parent.parent.toTop();
	}
}
//判断字符串是否为空
function isEmpty(str){
	if(str==undefined || str==null || str=="" || doTrim(str)=="")return true;
	return false;
}
//打开自定义alert
//打开自定义alert
function openAlert(title,content,aFun){
	parent.parent.parent.parent.aFunObj = aFun;
	setTimeout(function(){
		$("#alertContent",parent.parent.document).css("height","auto");
		if(isEmpty(title))title = titleMsg;
			$("#alertTitle",parent.parent.document).html(title);
		if(isEmpty(content))content = contentMsg;
			$("#alertContent",parent.parent.document).html(content);
		openMark2();
		var topH = parent.parent.document.body.scrollTop;
		var topH = parent.parent.document.body.scrollTop;
		var widW = parent.parent.parent.parent.document.body.clientWidth;
		var leftV = (widW - 500)/2;
		$(".alertCeng",parent.parent.document).css("left",leftV+"px");
		$(".alertCeng",parent.parent.document).css("top",(topH+200)+"px");
		$(".alertCeng",parent.parent.document).show();
		if($("#alertContent",parent.parent.document).height()>100){
			$("#alertContent",parent.parent.document).css("height",100);
		}
	},setTimeoutVal); 
}
//关闭自定义alert
function closeAlert(){
	closeMark2();
	$(".alertCeng",parent.parent.document).hide();
}
//打开自定义confirm
var confirmFun;
var clConfirmFun;
function openConfirm(title,content,fun,autoClose,closeFun,bt1,bt2){
	parent.parent.parent.parent.autoClose = autoClose;
	confirmFun = fun;
	parent.confirmFun = fun;
	parent.parent.confirmFun = fun;
	clConfirmFun = closeFun;
	parent.clConfirmFun = closeFun;
	parent.parent.clConfirmFun = closeFun;
	if(isEmpty(bt1))bt1="确 定";
	if(isEmpty(bt2))bt2="取 消";
	$("#cmok",parent.parent.parent.parent.document).val(bt1);
	$("#cmno",parent.parent.parent.parent.document).val(bt2);
	setTimeout(function(){
		if(!isEmpty(title))$("#confirmTitle",parent.parent.document).html(title);
		if(!isEmpty(content))$("#confirmContent",parent.parent.document).html(content);
		openMark2();
		var topH = parent.parent.document.body.scrollTop;
		var widW = parent.parent.parent.parent.document.body.clientWidth;
		var leftV = (widW - 500)/2;
		$(".confirmCeng",parent.parent.document).css("left",leftV+"px");
		$(".confirmCeng",parent.parent.document).css("top",(topH+200)+"px");
		$(".confirmCeng",parent.parent.document).show();
	},setTimeoutVal); 
}
//执行confirm确定方法
function doConfirmFun(){
	if(confirmFun==undefined){
		ifr.window.confirmFun();
		return;
	}
	confirmFun();
	//closeMark();
	//closeMark2();
}
function doClConfirmFun(){
	if(clConfirmFun==undefined){
		return;
	}
	clConfirmFun();
}
//关闭自定义confirm
function closeConfirm(){
	closeMark2();
	$(".confirmCeng",parent.document).hide();
}
//打开自定义弹出层ifr
function openIframe(url,heightVal,widthVal){
	setTimeout(function(){
		$(".openIframe",parent.document).css("height",heightVal+"px");
		$(".openIframe",parent.document).css("width",widthVal+"px");
		$("#oifr",parent.document).css("height",heightVal+"px");
		$("#oifr",parent.document).css("width",widthVal+"px");
		openMark();
		$("#oifr",parent.document).attr("src",url);
		$(".openIframe",parent.document).show();
		var topH = parent.parent.document.body.scrollTop;
		$(".openIframe",parent.document).css("top",(topH+50)+"px");
	},setTimeoutVal); 
}
//关闭自定义弹出层ifr
function closeIframe(){
	closeMark();
	$(".openIframe",parent.document).hide();
}
//打开自定义弹出层
function showOpenCeng(id,title,heightVal,widthVal){
	$("#"+id+"Title",parent.document).html(title);
	setTimeout(function(){
		$("#"+id,parent.document).css("height",heightVal+"px");
		$("#"+id,parent.document).css("width",widthVal+"px");
		parent.openMark();
		$("#"+id,parent.document).show();
		var topH = parent.parent.document.body.scrollTop;
		$("#"+id,parent.document).css("top",(topH+50)+"px");
	},setTimeoutVal); 
}
//关闭自定义弹出层
function closeCeng(){
	closeMark();
	$(".openCeng",parent.document).hide();
	$("#maskIfrDiv",parent.document).hide();
	$("#maskIfr",parent.parent.document).attr("src","");
}
//关闭自定义弹出层2
function closeCeng2(){
	closeMark();
	$(".openCeng",parent.document).hide();
	$("#maskIfrDiv",parent.document).hide();
}
//打开自定义弹出层
function toOpenCeng(url,title,heightVal,widthVal,topVal,leftVal){
	var srcVal = $("#maskIfr",parent.parent.document).attr("src");
	if(!isEmpty(srcVal))$("#maskIfr",parent.parent.document).attr("src","");
	if(parent.parent.parent.parent.userType==3 && url.indexOf("goToGroupTreeByIns")!=-1){
		widthVal = 800;
		topVal = 10;
	}
	setTimeout(function(){
		parent.openMark();
		$("#maskIfr",parent.parent.document).hide;
		$("#maskIfr",parent.parent.document).attr("src",url);
		$("#maskIfrTitle",parent.parent.document).html(title);
		$("#maskIfrDiv",parent.parent.document).css("height",heightVal+"px");
		$("#maskIfrDiv",parent.parent.document).css("width",widthVal+"px");
		$("#maskIfr",parent.parent.document).css("height",parseInt($("#maskIfrDiv",parent.parent.document).css("height"))-25);
		var topH = parent.parent.document.body.scrollTop;
		var widW = parent.parent.parent.parent.document.body.clientWidth;
		var leftV = (widW - widthVal)/2;
		$("#maskIfrDiv",parent.parent.document).css("left",leftV+"px");
		$("#maskIfrDiv",parent.parent.document).css("top",(topH+50)+"px");
		$("#maskIfrDiv",parent.parent.document).show();
		$("#maskIfr",parent.parent.document).show;
		if(!isEmpty(topVal)){
			$("#maskIfrDiv",parent.parent.document).css("top",(topH+topVal)+"px");
		}
		if(!isEmpty(leftVal)){
			$("#maskIfrDiv",parent.parent.document).css("left",leftVal+"px");
		}
	},setTimeoutVal); 
}
function setOpenCengHeight(hv){
	$("#maskIfrDiv",parent.parent.parent.parent.document).css("height",hv+210);
	$("#maskIfr",parent.parent.parent.parent.document).css("height",hv+190);
}
function setPH(){
	if(isEmpty(parent.parent.oldHeight) || parent.parent.oldHeight==0)
	parent.parent.oldHeight = parseInt($("#ifr",parent.parent.document).css("height"));
//	alert(parent.parent.oldHeight);
}
function setPH_P(){
//	alert(parent.parent.oldHeight);
	if(parent.parent.oldHeight != 0){
		if(parent.parent.editIfrHeight!=undefined)parent.parent.editIfrHeight(parent.parent.oldHeight);
	}
	//if($(".maskCss",parent.parent.document).css("display")=="none")) && $(".maskCss2",parent.parent.document).css("display")=="none"))
	if($(".maskCss",parent.parent.document).css("display")=="none" && $(".maskCss2",parent.parent.document).css("display")=="none")
	parent.parent.oldHeight = 0;
}
var allH1 = 0;
//打开遮罩图层
function openMark(){
	setPH();
	parent.maskFlag = 1;
	var height = parent.parent.parent.parent.getScrollHeight();
	parent.parent.parent.parent.allH1 = height;
	if(height<580)height=580;
	$(".maskCss",parent.parent.document).css("height",height+"px");
	$(".maskCss",parent.parent.document).show();
}
var allH2 = 0;
//打开遮罩图层2
function openMark2(){
	setPH();
	parent.maskFlag = 1;
	var height = parent.parent.parent.parent.getScrollHeight();;
	parent.parent.parent.parent.allH2 = height;
	if(height<580)height=580;
	$(".maskCss2",parent.parent.document).css("height",height+"px");
	$(".maskCss2",parent.parent.document).show();
}
//关闭遮罩图层
function closeMark(){
	$(".maskCss",parent.parent.document).hide();
	$("#maskIfr",parent.parent.document).attr("src","#");
	parent.maskFlag = 0;
	$(".maskCss",parent.parent.document).css("height",allH1+"px");
	setPH_P()
}
//关闭遮罩图层2
function closeMark2(){
	$(".maskCss2",parent.parent.document).hide();
	parent.maskFlag = 0;
	$(".maskCss2",parent.parent.document).css("height",allH2+"px");
	setPH_P()
}
//获取页面总高度
function getPageHeight(){
	var height = document.body.scrollHeight;
	if($('body',parent.document).attr("id")=='main'){
		height = parent.document.body.scrollHeight;
	}
	if($('body',parent.parent.document).attr("id")=='main'){
		height = parent.parent.document.body.scrollHeight;
	}
	return height; 
}

//锁定按钮，参数：按钮对象，锁定时间
var buttonBg;
var buttonVal;
var lockMis;
function lockButton(obj,time){
    buttonBg = $(obj).css("background-color");
    buttonVal = $(obj).val();
    $(obj).attr("disabled",true);
    $(obj).css("cursor","default");
    $(obj).css("background-color","#999999");
    if(isEmpty(time))return;
    $(obj).val(buttonVal+time--);
    lockMis = setInterval(function(){
        $(obj).attr("disabled",true);
        $(obj).css("cursor","default");
        $(obj).css("background-color","#999999");
        $(obj).val(buttonVal+time--);
        if(time<=-1){
            $(obj).attr("disabled",false);
            $(obj).css("background-color",buttonBg);
            $(obj).css("cursor","pointer");
            $(obj).val(buttonVal);
            clearInterval(lockMis);
            lockMis = undefined;
        }
    },1000);
}
function cancelLockButtonByID(id,val,bg){
	cancelLockButtonByObj($("#"+id),val,bg);
}

function cancelLockButtonByObj(obj,val,bg){
	if(!isEmpty(bg))buttonBg = bg;
	if(!isEmpty(val))buttonVal = val;
	if(isEmpty(buttonBg))buttonBg = "#5381CE";
	if(isEmpty(val))val = $(obj).val();
	$(obj).attr("disabled",false);
	$(obj).css("background-color",buttonBg);
	$(obj).css("cursor","pointer");
	$(obj).val(buttonVal);
}

var linkCg;
//根据ID锁住超链接
function lockLinkByID(id){
	lockLinkByObj($("#"+id));
}
//根据对象锁住超链接
function lockLinkByObj(obj){
	linkCg = $(obj).css("color");
    $(obj).attr("disabled",true);
    $(obj).css("color","#B4B4B4");
    $(obj).css("cursor","default");
    $(obj).attr("onclick","");
    $(obj).attr("href","javascript:void(0)");
    var imgObj = $(obj).find("img");
    $(imgObj).attr("src",ctx+"/css/img/icon/no.gif");
}
//根据ID解除锁定超链接
function cancelLockLinkID(id){
	cancelLockLinkObj($("#"+id));
}
//根据对象解除锁定超链接 -- 有问题，解锁的时候无法把原有的onclick事件还原,也无法把原有的img还原
function cancelLockLinkObj(obj){
    $(obj).attr("disabled",false);
    $(obj).css("color","");
    $(obj).css("cursor","pointer");
}
//打开loading层
function openLoading(){
	var height = parent.parent.parent.parent.getScrollHeight();
    parent.parent.parent.parent.allH1 = height;
    if(height<580)height=580;
    $(".loadingDiv",parent.parent.document).css("height",height+"px");
    $(".loadingDiv",parent.parent.document).show();
    $(".loadingImg",parent.parent.document).show();
}
//关闭loading层
function closeLoading(){
	$(".loadingDiv",parent.parent.document).css("height","580px");
    $(".loadingDiv",parent.parent.document).hide();
    $(".loadingImg",parent.parent.document).hide();
}


//前后去空格
//此处为独立函数
function LTrim(str)
{
	if(!isString(str))return str;
  var i;
  for(i=0;i<str.length;i++)
  {
      if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
  }
  str=str.substring(i,str.length);
  return str;
}
function RTrim(str)
{
	if(!isString(str))return str;
  var i;
  for(i=str.length-1;i>=0;i--)
  {
      if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
  }
  str=str.substring(0,i+1);
  return str;
}
function doTrim(str)
{
	if(!isString(str))return str;
  return LTrim(RTrim(str));
}

//获取当前日期 。格式为2014-05-14
function getFormatDate(addYear,addMonth,addDay){
   var day=new Date();
   var Year=0;
   var Month=0;
   var Day=0;
   var CurrentDate="";
   Year       = day.getYear();
   if(Year<1900)Year = Year+1900;
   if(!isEmpty(addYear))Year = Year+addYear;
   Month      = day.getMonth()+1;
   Day        = day.getDate();
   CurrentDate = Year + "-";
   if (Month >= 10 ){CurrentDate = CurrentDate + Month + "-";}
   else{CurrentDate = CurrentDate + "0" + Month + "-";}
   if(Day >= 10){CurrentDate = CurrentDate + Day ;}
   else{CurrentDate = CurrentDate + "0" + Day ;}
   return CurrentDate;
} 
//获取当前日期 。格式为2014-05-14 21:52:13
function getFormatDate2(){
   var day=new Date();
   var Year=0;
   var Month=0;
   var Day=0;
   var Hour = 0;
   var Minute = 0;
   var Second = 0;
   var CurrentDate="";
   Year       = day.getYear();
   if(Year<1900)Year = Year+1900;
   Month      = day.getMonth()+1;
   Day        = day.getDate();
   Hour       = day.getHours();
   Minute     = day.getMinutes();
   Second     = day.getSeconds();
   CurrentDate = Year + "-";
   if (Month >= 10 ){CurrentDate = CurrentDate + Month + "-";}
   else{CurrentDate = CurrentDate + "0" + Month + "-";}
   if(Day >= 10){CurrentDate = CurrentDate + Day ;}
   else{CurrentDate = CurrentDate + "0" + Day ;}
   if(Hour >=10){CurrentDate = CurrentDate +" "+ Hour;}
   else{CurrentDate = "0" + Hour ;}
   if(Minute >=10){CurrentDate = CurrentDate + ":" + Minute;}
   else{CurrentDate = CurrentDate + ":0" + Minute;}     
   if(Second>=10){CurrentDate = CurrentDate + ":" + Second;}
   else{CurrentDate = CurrentDate + ":0" + Second;}
   return CurrentDate;
} 

function getFormatDate3(addYear,addMonth,addDay){
   var day=new Date();
   if(addMonth!=undefined && addMonth>=-11 && addMonth<=11){
	   m = day.getMonth();
	   m = m+addMonth;
	   if(m<0){
		   day.setMonth(11+m);
		   day.setYear(day.getYear()-1);
	   }else if(m>11){
		   day.setMonth(m-11);
		   day.setYear(day.getYear()+1);
	   }else{
		   day.setMonth(m);
	   }
   }
   var Year=0;
   var Month=0;
   var Day=0;
   var CurrentDate="";
   Year       = day.getYear();
   if(Year<1900)Year = Year+1900;
   if(!isEmpty(addYear))Year = Year+addYear;
   Month      = day.getMonth()+1;
   Day        = day.getDate();
   CurrentDate = Year + "-";
   if (Month >= 10 ){CurrentDate = CurrentDate + Month + "-";}
   else{CurrentDate = CurrentDate + "0" + Month + "-";}
   if(Day >= 10){CurrentDate = CurrentDate + Day ;}
   else{CurrentDate = CurrentDate + "0" + Day ;}
   return CurrentDate;
} 
function last7Day(){
	var date = new Date();
	date.setDate(date.getDate()-8);
	return getFormatDateYMD(date); 
}
function getFormatDateYMD(day){
	   var Year=0;
	   var Month=0;
	   var Day=0;
	   var Hour = 0;
	   var Minute = 0;
	   var Second = 0;
	   var CurrentDate="";
	   Year       = day.getYear();
	   if(Year<1900)Year = Year+1900;
	   Month      = day.getMonth()+1;
	   Day        = day.getDate();
	   Hour       = day.getHours();
	   Minute     = day.getMinutes();
	   Second     = day.getSeconds();
	   CurrentDate = Year + "-";
	   if (Month >= 10 ){CurrentDate = CurrentDate + Month + "-";}
	   else{CurrentDate = CurrentDate + "0" + Month + "-";}
	   if(Day >= 10){CurrentDate = CurrentDate + Day ;}
	   else{CurrentDate = CurrentDate + "0" + Day ;}
	   return CurrentDate;
	}

	function reDate(){//最近7天
		$("#stDate").val(last7Day());
		var date = new Date();
		date.setDate(date.getDate()-1);
		$("#edDate").val(getFormatDateYMD(date));
	}


//计算天数差 时间格式 yyyy-MM-dd 字符串
function getDayNumber(s1,s2)
{
	s1 = s1.replace(/-/g, "/"); 
	s2 = s2.replace(/-/g, "/"); 
	s1 = new Date(s1);
	s2 = new Date(s2);
	var times= s2.getTime() - s1.getTime(); 
	var days = parseInt(times/ (1000 * 60 * 60 * 24));
	return days;
}


function FormatDateTime(obj, IsMi) {   
	var myDate = new Date(obj);   
	var year = myDate.getFullYear();  
	var month = ("0" + (myDate.getMonth() + 1)).slice(-2);  
	var day = ("0" + myDate.getDate()).slice(-2);  
	var h = ("0" + myDate.getHours()).slice(-2);  
	var m = ("0" + myDate.getMinutes()).slice(-2);  
	var s = ("0" + myDate.getSeconds()).slice(-2);   
	var mi = ("00" + myDate.getMilliseconds()).slice(-3);  
	if (IsMi == true) {   
		return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;   
	}   
	else {   
		return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s + "." + mi;   
	}  
}

//弹出层里，获取嵌套页面对象
function getCengSonObj(id){
	return $("#ifr",parent.document).contents().find('#'+id);
}

//设置树上所有节点都是收起闭状态
function closeAllNode(list){
	if(list==undefined || list.length==0)return list;
	list.open = false;
	for(var i=0;i<list.length;i++){
		var nd = list[i];
		if(nd==undefined)continue;
		nd.open = false;
		if(nd.children!=undefined){
			nd.children = closeAllNode(nd.children);
		}
	}
	return list;
}

//限制列表页面高度
function editGunXH(hval){
	var heightVal = parseInt($(".gunX").css("height"));
	if(heightVal>hval)$(".gunX").css("height",hval+"px");
}

//文本框只允许输入数字
function isDigit(){ 
	return ((event.keyCode>=48)&&(event.keyCode<=57));
}

////修改主页面的当前位置
function editPlace(one,two,three,four){
	editPlaceOne(one);
	editPlaceTwo(two);
	editPlaceThree(three);
	editPlaceFour(four);
}

//修改主页面的当前位置1
function editPlaceOne(one){
	if(!isEmpty(one)){
		$("#place1",parent.parent.parent.parent.document).html("<img src='"+ctx+"/css/img/icon/rightBlue.png'/>"+one);
	}else{
		$("#place1",parent.parent.parent.parent.document).html("");
	}
}
//修改主页面的当前位置2
function editPlaceTwo(two){
	if(!isEmpty(two)){
		$("#place2",parent.parent.parent.parent.document).html("<img src='"+ctx+"/css/img/icon/rightBlue.png'/>"+two);
	}else{
		$("#place2",parent.parent.parent.parent.document).html("");
	}
}
//修改主页面的当前位置3
function editPlaceThree(three){
	if(!isEmpty(three)){
		$("#place3",parent.parent.parent.parent.document).html("<img src='"+ctx+"/css/img/icon/rightBlue.png'/>"+three);
	}else{
		$("#place3",parent.parent.parent.parent.document).html("");
	}
}
//修改主页面的当前位置4
function editPlaceFour(four){
	if(!isEmpty(four)){
		$("#place4",parent.parent.parent.parent.document).html("<img src='"+ctx+"/css/img/icon/rightBlue.png'/>"+four);
	}else{
		$("#place4",parent.parent.parent.parent.document).html("");
	}
}
//清空当前位置
function clearPlace(){
	$("#place1",parent.parent.parent.parent.document).html("");
	$("#place2",parent.parent.parent.parent.document).html("");
	$("#place3",parent.parent.parent.parent.document).html("");
	$("#place4",parent.parent.parent.parent.document).html("");
}

//获取滚动条高度
function getScrollTop(){    
	var scrollTop=0;    
	if(document.documentElement&&document.documentElement.scrollTop){        
		scrollTop=document.documentElement.scrollTop;    
	}else if(document.body){        
		scrollTop=document.body.scrollTop;
	}    
	return scrollTop;
}

//获取页面总高度
function getScrollHeight(){
    return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}

//验证邮箱格式
function checkMail(mailaddress)   
{   
    var result=mailaddress.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);   
    if(result==null) return false;   
    return true;   
}
//验证身份证后六位
function checkCardNo(cardNo){
	 var result=cardNo.match(/^[0-9]{5}[xX0-9]$/);   
     if(result==null) return false;   
     return true;   
}
//验证手机格式
function checkMobile(sMobile){ 
	 //var result=sMobile.match(/^[1][3,4,5,8][0-9]{9}$/);  
	 //因增加新的运行商号码段，所以取消中间号码的验证
	 var result=sMobile.match(/^[1][0-9]{10}$/); 
	    if(result==null) return false;   
	    return true;   
} 

//设为首页
function SetHome(obj,vrl){
    try{
            obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
         if(window.netscape) {
               try {
                       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
               }
               catch (e) {
                       alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
               }
               var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
               prefs.setCharPref('browser.startup.homepage',vrl);
          }
    }
}

//6位数字验证码验证，离开焦点时触发，需要参入id,值，错误描述
function onblurCommon(id, val, descVal) {
	var flag = checkNumberForN(val);
	if (!isEmpty(val) && !flag) {
		$("#" + id + "Error").html(descVal);
		okN(id);
	} else if (isEmpty(val)) {
		$("#" + id + "Error").hide();
		$("#" + id + "Ok").hide();
		$("#" + id + "Prompt").hide();
	}else{
		okY(id);
	}
}

//密码验证，离开焦点时触发，需要参入id,值，错误描述
function onblurCommonPwd(id, val, descVal) {
	var flag = checkPwdForN(val);
	if (!isEmpty(val) && !flag) {
		$("#" + id + "Error").html(descVal);
		okN(id);
	} else if (isEmpty(val)) {
		$("#" + id + "Error").hide();
		$("#" + id + "Ok").hide();
		$("#" + id + "Prompt").hide();
	}else{
		okY(id);
	}
}

//密码验证，离开焦点时触发，需要参入id,值，错误描述
function onblurCommonName(id, val, descVal) {
	var flag = checkNameForN(val);
	if (!isEmpty(val) && !flag) {
		$("#" + id + "Error").html(descVal);
		okN(id);
	} else if (isEmpty(val)) {
		$("#" + id + "Error").hide();
		$("#" + id + "Ok").hide();
		$("#" + id + "Prompt").hide();
	}else{
		okY(id);
	}
}


//验证手机和邮箱验证码格式
function checkNumberForN(numberargs) {
	var result = numberargs.match(/^\d{6}$/);
	if (result == null)
		return false;
	return true;
}

//密码格式验证,包括数字字符提示字符(去掉空格)
function checkPwdForN(pwdval, n) {
//	var result = numberargs.match(/^[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]{6,15}$/);
//	if (result == null)
//		return false;
//	return true;
	var pwdReg = /(?=^.{8,20}$)(?=.*[a-z]{1,})(?=.*[0-9]{1,})(?=.*[A-Z]{1,}).*$/;            	
	if(!pwdReg.test(pwdval)) {
		return false;
	}
	return true;
}


//用户名格式验证,包括数字字符提示字符(去掉空格)
function checkNameForN(numberargs, n) {
	var result = numberargs.match(/^[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]{4,30}$/);
	if (result == null)
		return false;
	return true;
}

// 用户名格式验证,若用户输入11位数字，直接报“用户名重复”
function checkNameElevenNum(userName) {
	var reg = new RegExp(/^\d{11}$/);
	if(reg.test(userName)) {
		return true;
	} else {
		return false;
	}
}


//判断JS变量类型
function isNumeric(v){return (v && v.constructor == Number);}
function isDate(v){return (v && v.constructor == Date);}
function isString(v){return (v && v.constructor == String);}

//比较日期大小
function dateCompare(startdate,enddate)   
{   
var starttime =new Date(startdate.replace(/\-/g, "\/"));  
var lktime=new Date(enddate.replace(/\-/g, "\/"));  
if(starttime>=lktime)    
{   
return false;   
}   
else  
return true;   
}  

function isIE(){
	if ((navigator.userAgent.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') < 0) && navigator.userAgent.indexOf("Trident/7.0")==-1)return true;
	return false;
}

function isIE2(){
	if ((navigator.userAgent.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') < 0))return true;
	return false;
}

//判断日期版本
function iEVer(){
	if ((navigator.userAgent.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') < 0)){
		var browser=navigator.appName
	    var b_version=navigator.appVersion
	    var version=b_version.split(";");
	    var trim_Version=version[1].replace(/[ ]/g,"");
	    return trim_Version;
	}
	return 0;
}

//树节点名省略
function setTreeNameLength(list,treeObj,num){
    if(list==undefined || list.length==0)return list;
    for(var i=0;i<list.length;i++){
        var obj = list[i];
        var name = obj.name;
        obj.title=name;
        if(name.length>num){
            name = name.substr(0,(num-3))+"...";
        }
        obj.name = name;
        treeObj.updateNode(obj);
        var sonList = obj.children;
        if(sonList!=undefined && sonList.length!=0){
        	var nextNum = num-2;
        	if(nextNum<3)nextNum = 3;
            setTreeNameLength(sonList,treeObj,nextNum);
        }
    }
    return list;
}

function checkKeyForFloat(value, e) {  //只允许输入数字和小数点
    var isOK = false;  
    var key = window.event ? e.keyCode : e.which;  
    if ((key > 95 && key < 106) ||                  //小键盘上的0到9  
    (key > 47 && key < 60) ||                   //大键盘上的0到9  
    (key == 110 && value.indexOf(".") < 0) ||   //小键盘上的.而且以前没有输入.  
    (key == 190 && value.indexOf(".") < 0) ||   //大键盘上的.而且以前没有输入.  
    key == 8 || key == 9 || key == 46 || key == 37 || key == 39     //不影响正常编辑键的使用(8:BackSpace;9:Tab;46:Delete;37:Left;39:Right)  
) {  
        isOK = true;  
    } else {  
        if (window.event) //IE    
        {  
            e.returnValue = false;   //event.returnValue=false 效果相同.    
        }  
        else //Firefox    
        {  
            e.preventDefault();  
        }  
    }  
    return isOK;  
} 

function cardFormat(obj,ev){//银行卡文本框格式化
	var oW=obj.value;
	var oEvent=ev || window.event; 
	if(oEvent.keyCode==8){
		if(oW){
			for(var i=0;i<oW.length;i++)
			var newStr=oW.replace(/\s$/g,'');
			obj.value=newStr;
		}
	}else{
		if(!isEmpty(oW)){
			for(var i=0;i<oW.length;i++){
				var arr=oW.split('');
				if((i+1)%5==0)arr.splice(i,0,' ');
			}
			obj.value=arr.join('');
		}
	}
}

//字符串转代码
function conversionCode(str){
	var jsonList = str.replace(/\n|\r/g,"").replace(/<\/?.+?>/g,"");
	str = eval("(" + jsonList + ")");
	return str;
}	

function clearNoNum2(obj){//只允许输入数字或者2位以内的小数
	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字而不是
	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
	}

function getDayNumber(date1,date2){//对比两个日期的天数差距
	  var year1 =  date1.substr(0,4);
	  var year2 =  date2.substr(0,4); 
	  var month1 = date1.substr(5,2);
	  var month2 = date2.substr(5,2);
	  
	  var day1 = date1.substr(8,2);
	  var day2 = date2.substr(8,2);
	  
	  temp1 = year1+"/"+month1+"/"+day1;
	  temp2 = year2+"/"+month2+"/"+day2;
	  
	  var dateaa= new Date(temp1); 
	  var datebb = new Date(temp2); 
	  var date = datebb.getTime() - dateaa.getTime(); 
	  var time = Math.floor(date / (1000 * 60 * 60 * 24));
	  return time;

	 }

function inNum(obj){   // 值允许输入一个小数点和数字
	  obj.value = obj.value.replace(/[^\d.]/g,"");     //先把非数字的都替换掉，除了数字和.
	  obj.value = obj.value.replace(/^\./g,"");         //必须保证第一个为数字而不是.
	  obj.value = obj.value.replace(/\.{2,}/g,".");   //保证只有出现一个.而没有多个.
	  obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");    //保证.只出现一次，而不能出现两次以上
	}

var phoneInpVal = "请输入验证码";
var sendFund;
var subFund;
function closePhone(){
	$("#phoneMask,#phoneTb").remove();
}
function openPhone(num,sendFun,subFun,arg){
	sendFund = sendFun;
	subFund = subFun;
	var content = "<div id=phoneMask></div>"+
					"<table id=phoneTb>"+
					"<tr><td><center>"+
						"<table id=phoneTitle class=yinying>"+
							"<tr>"+
								"<td align=left>手机验证</td>"+
								"<td align=right><a onclick='closePhone();'>x</a></td>"+
							"</tr>"+
						"</table>"+
						"<div id=phoneContent class=yinying>"+
							"<div style='height:10px;'></div>"+
							"<table>"+
								"<tr>"+
									"<th width=30% height=40>手机号：</th>"+
									"<td>"+num+"</td>"+
									"<input id='resPhone' type='hidden' value='" + num + "'/>" +
								"</tr>"+
								"<tr>"+
									"<th>验证码：</th>"+
									"<td>"+
										"<input id=phoneInp maxlength=6 value='"+phoneInpVal+"' onfocus='if(this.value==phoneInpVal)this.value=\"\";' onblur='if($.trim(this.value)==\"\")this.value=phoneInpVal'/>"+
										"<input id=phoneYZ type=button value=获取验证码  onclick='sendFund(this);' />"+
									"</td>"+
								"</tr>"+
								"<tr>"+
									"<td></td>"+
									"<td><input id=phoneTZ type=button value=' 提   交 ' onclick='subFund(\""+arg+"\");'/></td>"+
								"</tr>"+
							"</table>"+
							"<div style='height:10px;'></div>"+
						"</div>"+
					"</center></td></tr>"+
				"</table>";
	$("body").append(content);
}

function authenticationCallBack_Phone_Dn(callBack,arg,phoneNum,sendFun,useFlag) {
	  //是否弹出证书判断
	  $.ajax({
			type : "POST",
			url : ctx + "/accountAdjustCtrl/checkUserCertDnOrMobilePop",
			data : {dateTemp:encodeURI(encodeURI(new Date()))},
			success : function(msg) {
				var needPopCertFlag = msg.safeType;
				//弹出数字证书验证
				if(needPopCertFlag == "DN" || 1==useFlag){
					$("#dn").val("");
    				try {
    						var SubjectFilter = "";
    						var IssueFilter = "";
    						var CertSubjectDN = CryptoAgency.SelectSignCertificate(SubjectFilter, IssueFilter);
    						if(!CertSubjectDN){
    							var LastErrorDesc = CryptoAgency.GetLastErrorDesc();
    						    alert(LastErrorDesc);
    						    return;
    						}
    						var objSelectedCertSubjectDN = SelectObjctById("dn");
    						objSelectedCertSubjectDN.value = CertSubjectDN;
    						callBack(arg);
    					}
    					catch (e) {
    						var LastErrorDesc = CryptoAgency.GetLastErrorDesc();
    						alert(LastErrorDesc);
    					}
				}else if(needPopCertFlag == "MB"){
					if(phoneNum == ""){
						phoneNum = msg.phone;
					}
					openPhone(phoneNum,sendFun,callBack,arg);
				}else{
					callBack(arg);
					/*openConfirm("<spring:message code='reminder'/>", "你没有退货的权限，是否要继续？", function(){ 
  						callBack(arg);
  		   			}); */
				}
		}});
 }

 function strlen(str){//判断JS字符串有几个字符，中文为2字符  
	    var len = 0;  
	    for (var i=0; i<str.length; i++) {   
	     var c = str.charCodeAt(i);   
	    //单字节加1   
	     if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
	       len++;   
	     }   
	     else {   
	      len+=2;   
	     }   
	    }   
 return len;  
}  	
 
 function subStrFun(str,num){//截取字符串，中文算2位
  	var val = "";
  	var len = 0;  
  	var strList = str.split("");
  	for (var i=0; i<str.length; i++) {   
		     var c = str.charCodeAt(i);  
		    //单字节加1   
		     if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
		       len++;   
		     }   
		     else {   
		      len+=2;   
		     } 
		    if(len>num){
		    	return val;
		    }else{
		    	val+= strList[i];
		    }
		 }   
  }
 
 function checkPWD(val){
	 var pwdError = false;
	 $.ajax({
		   type: "POST",
		   url: ctx+"/uisWebLogin/validatepwdforware",
		   data: "userPwd="+val,
		   async: false,
		   success: function(res){
			   if("checkwareError"==res)
				 pwdError = true;
		   }
		});
	 return pwdError;
 }
 
 

